<?php
class Wishlists extends MX_Controller
{    
    function __construct() {
        parent::__construct();
    }
    function index()
    {
        $data['a'] = 'a';
        $this->common->load_template('wishlists_index',$data);
    }
    // Lay ra danh sach cac mon an yeu thich
    function product()
    {
        $product = new Product();                  
        $product->include_related('term_taxonomy',array('term_id','taxonomy'))
                ->where_related('term_taxonomy', 'taxonomy', 'wishlistproduct')
                ->where_related('term_taxonomy', 'term_id',62);  
        //$list_child_product->include_related('term_taxonomy_product',array('term_order'));                                           
        $product->select('hd_term_taxonomies_products.term_order');
        $product->select('hd_term_taxonomies_products.id AS term_tax_product_id');
        $product->order_by('hd_term_taxonomies_products.term_order','ASC');
        $list_child_product = $product->get();  
        $data['list_child_product'] = $list_child_product; 
        $data['flag'] = true;
        // check login
        if(!$this->session->userdata('login'))
        {
            $data['check_login'] = false;
        }
        else 
        {
            $data['check_login'] = true;
        }
        $this->common->load_template('wishlists_product',$data);
    }
    // Lay ra danh sach cac nha hang yeu thich
    function restaurent()
    {
        $list_child_restaurent = new Restaurent();                       
        
        $list_child_restaurent->include_related('term_taxonomy',array('term_id','taxonomy'))
                ->where_related('term_taxonomy', 'taxonomy', 'wishlistrestaurent')
                ->where_related('term_taxonomy', 'term_id', 61);                  
        $list_child_restaurent->select('hd_term_taxonomies_restaurents.term_order');
        $list_child_restaurent->select('hd_term_taxonomies_restaurents.id AS term_tax_restaurent_id');
        $list_child_restaurent->order_by('hd_term_taxonomies_restaurents.term_order','ASC');
        $data['list_child_restaurent'] = $list_child_restaurent->get();  
        $data['flag'] = true; 
        // check login
        if(!$this->session->userdata('login'))
        {
            $data['check_login'] = false;
        }
        else 
        {
            $data['check_login'] = true;
        }
        $this->common->load_template('wishlists_restaurent',$data);
    }
    // them mon an yeu thich vao wishlist
    function add_product_wishlist()
    {
        $id = $this->input->post('id');        
        $object_id = $this->input->post('object_id');
        $product = new Product();
        $product->get_by_id($id);
        $term_taxonomy =  new Term_taxonomy();
        $term_taxonomy->where('taxonomy','wishlistproduct');
        $term_taxonomy->where('user_id',$object_id)->get();
        $term_taxonomy->save($product);

        echo '<a class="remove_product_wishlist" value="'.$id.'" href="">Remove Wishlist</a>';
    }
    // Xoa mon an khoi wishlist
    function remove_product_wishlist()
    {
        $id = $this->input->post('id');
        $object_id = $this->input->post('object_id');
        $product = new Product();
        $product->get_by_id($id);
        $term_taxonomy =  new Term_taxonomy();
        $term_taxonomy->where('taxonomy','wishlistproduct');
        $term_taxonomy->where('user_id',$object_id)->get();
        $term_taxonomy->delete($product);
        echo '<a class="add_product_wishlist" value="'.$id.'" href="#">Add to wishlist</a>';
    }
    // Them nha hang yeu thich vao wishlist
    function add_restaurent_wishlist()
    {
        $id = $this->input->post('id');
        $object_id = $this->input->post('object_id');
        $restaurent = new Restaurent();
        $restaurent->get_by_id($id);
        $term_taxonomy =  new Term_taxonomy();
        $term_taxonomy->where('taxonomy','wishlistrestaurent');
        $term_taxonomy->where('user_id',$object_id)->get();
        $term_taxonomy->save($restaurent);

        echo '<a class="remove_restaurent_wishlist" value="'.$id.'" href="">Remove Wishlist</a>';
    }
    //Xoa nha hang yeu thich khoi wishlist
    function remove_restaurent_wishlist()
    {
        $id = $this->input->post('id');
        $object_id = $this->input->post('object_id');
        $restaurent = new Restaurent();
        $restaurent->get_by_id($id);
        $term_taxonomy =  new Term_taxonomy();
        $term_taxonomy->where('taxonomy','wishlistrestaurent');
        $term_taxonomy->where('user_id',$object_id)->get();
        $term_taxonomy->delete($restaurent);
        echo '<a class="add_restaurent_wishlist" value="'.$id.'" href="#">Add to wishlist</a>';
    }        
}
?>
    